import React, { useContext, useEffect, useState } from 'react'
import { MyContext } from '../../App'
import { reqgetcountdown, reqgetgroupon, reqgetnew, reqgetseckill, reqShouYe } from '../../http/api'
import Header from '../../components/Header/Header'
import Cate from "./components/cate/Cate"
import Groupon from "./components/groupon/Groupon"
import Countdown from "./components/countdown/Countdown"
import Seckill from "./components/seckill/Seckill"
import Indexgoods from "./components/indexgoods/Indexgoods"

const Home = () => {
  //1。分类的数据
  const [cate, setcate] = useState([])
  const [groupon, setGroupon] = useState([])
  const [countdown, setCountdown] = useState([])
  const [seckill, setSeckill] = useState([])
  const [shouye, setShouye] = useState([])
  const [n, setn] = useState(0)
  const { state: { pre }, dispatch } = useContext(MyContext)

  useEffect(() => {
    //新人
    reqgetnew().then(res => {
      setcate(res.data.list)
    })
    //万人团
    reqgetgroupon().then(res => {
      setGroupon(res.data.list)
    })
    //倒计时
    reqgetcountdown().then(res => {
      setCountdown(res.data.list)
    })
    //秒杀
    reqgetseckill().then(res => {
      setSeckill(res.data.list)
    })
    //商品信息首页
    reqShouYe().then(res => {
      setShouye(res.data.list)
    })
  }, [])
  //点击切换
  const changeHomeN = (e) => {
    console.log('====================================');
    console.log(e);
    console.log('====================================');
    setn(e)
  }

  return (
    <div>
      <Header text="首页"></Header>
      <div className='con'>
        <Cate cate={cate} pre={pre}></Cate>
        <Groupon groupon={groupon} pre={pre}></Groupon>
        <Countdown countdown={countdown} pre={pre}></Countdown>
        <Seckill seckill={seckill} pre={pre}></Seckill>
        <Indexgoods shouye={shouye} pre={pre} n={n} changeHomeN={changeHomeN}></Indexgoods>
      </div>
    </div>
  )
}
export default Home;